package com.fqy.thread02.compare;

/**
 * User: fqy
 * Date: 2021/9/1
 * Time: 21:26
 * Describe:1 synchronized是java的内置关键字而ReentrantLock时java5以后的新发布的类
 *          2 synchronized一旦申请，如果获取不到锁会一直阻塞，这个阻塞的过程，用户无法控制
 */
public class CompareLockAndSync {

    public static void main(String[] args) {

        Resource resource = new Resource();

        new Thread(()->{
            for (int i = 0; i < 5; i++) {
                resource.resource01();
            }
        },"t1").start();

        new Thread(()->{
            for (int i = 0; i < 5; i++) {
                try {
                    resource.resource02();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"t2").start();
    }
}
